package com.bowen.security.rsa.downstream;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.bowen.security.rsa.model.AuthRequest;
import com.bowen.security.rsa.util.RsaUtil;
import com.bowen.test.TestUpStreamModel;
import com.bowen.util.RandomUtils;

/**
 * 上游系统入参
 * 
 * @author Bowen
 * @since 2021-12-03 17:12:20
 */
public class DownStreamClient implements com.bowen.security.rsa.Client {

  /**
   * 解密
   * 
   * @param data  加密串
   * @param clazz 对线class
   * @return 值对象
   */
  public <T extends AuthRequest> T decrypt(Class<T> clazz, String data) {
    return RsaUtil.decrypt(clazz, data);
  }

  /**
   * 加密
   * 
   * @param <T>  继承 AuthRequest
   * @param data 待加密对象
   * @return 加密串
   */
  @Override
  public <T extends AuthRequest> String encryption(T data) {
    return null;
  }

  /**
   * 加密
   */
  @Override
  public <T extends AuthRequest> String encryption(T data, String downPublicKey, String upPrivateKey) {
    return null;
  }

  public static void main(String[] args) {
    try {
      // 入参测试

      // 1.入参封装
      TestUpStreamModel res = RandomUtils.setPro(TestUpStreamModel.class);
      res.setAppid("123456");
      JSONObject jsonObject = JSON.parseObject(JSONObject.toJSONString(res));
      System.out.println(jsonObject.toJSONString());
      // 2.加密
      String encryptionStr = RsaUtil.encryption(res, "123456");
      System.out.println(encryptionStr);
      // 3.解密
      TestUpStreamModel decrypt = RsaUtil.decrypt(TestUpStreamModel.class, encryptionStr);
      System.out.println(JSONObject.toJSONString(decrypt));
    } catch (Exception e) {
      e.printStackTrace();
    }
  }

}
